﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using log4net;
using TFXK.BLL;
using TFXK.Model;
using TFXK.Common;

public partial class MyControls_SearchControl : System.Web.UI.UserControl
{
    private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
    private static readonly CategoryBLL bllCategory = new CategoryBLL();
    private static readonly TravelLinesBLL bllTravelLines = new TravelLinesBLL();
    private static readonly OrdersBLL bllOrder = new OrdersBLL();
    int rowCount = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {
                BindHotKeys();
                BindTeJiaLines();
            }
        }
        catch (Exception ex)
        {
            log.Error(ex.Message);
        }
    }
    //绑定热门词
    public void BindHotKeys()
    {
        rptHotKey.DataSource = bllCategory.GetAllChildByCodeNoPar("hotKeys");
        rptHotKey.DataBind();
    }

    //绑定特价 推荐
    public void BindTeJiaLines()
    {
        rptTeJia.DataSource = bllTravelLines.GetWebList(7, 1, "isTeJia=1", out rowCount);
        rptTeJia.DataBind();

        this.rtpTuiJian.DataSource = bllTravelLines.GetWebList(7, 1, "isTuiJian=1", out rowCount);
        rtpTuiJian.DataBind();
    }
    public string GetLineLink(object tids, object id)
    {
        int tid = int.Parse(tids + "");
        if (tid == 41)
        {
            return "GN_TravelInfo.aspx?Key=" + id;
        }
        else if (tid == 42)
        {
            return "CJ_TravelInfo.aspx?Key=" + id;
        }
        else if (tid == 43)
        {
            return "ZY_TravelInfo.aspx?Key=" + id;
        }
        else if (tid == 44)
        {
            return "YL_TravelInfo.aspx?Key=" + id;
        }
        else
        {
            return "GN_TravelInfo.aspx?Key=" + id;
        }
    }
    //提交diy
    protected void btnSaveDiy_Click(object sender, EventArgs e)
    {
        Orders orderTemp = new Orders();
        string orderNum = "";
        if (ddlUNum.SelectedIndex == 0)
        {
            orderNum = "预定数量少于3 ";
        }
        else
        {
            orderNum = "预定数量大于3 ";
        }
        string address = StringUtil.HtmlEncode(txtAddress.Value);
        string tel = StringUtil.HtmlEncode(txtPhone.Value);
        string orderdate = StringUtil.HtmlEncode(txtDate.Value);
        string des = StringUtil.HtmlEncode(txtDes.Value);
        string userName = StringUtil.HtmlEncode(txtUserName.Value);
        
        if (string.IsNullOrEmpty(address) || string.IsNullOrEmpty(tel))
        {
            Msg.Show("输入不完整！");
            return;
        }
        else
        {
            orderTemp.createDate = DateTime.Now;
            orderTemp.customID = 0;
            try
            {
                orderTemp.orderDate = DateTime.Parse(orderdate);
            }
            catch
            {
                Msg.Show("日期格式输入不正确！");
                return;
            }
            orderTemp.orderDes = orderNum + des;
            orderTemp.orderNum = 0;
            orderTemp.orderState = 0;
            orderTemp.orderType = 2;
            orderTemp.parentID = 0;
            orderTemp.userName = userName;
            orderTemp.userSex = 0;
            orderTemp.userTel = tel;
            int row = bllOrder.Add(orderTemp);
            if (row > 0)
            {
                Msg.Show("DIY信息提交成功！我们将尽快与您取得联系");
            }
        }
    }
    //protected void btnSearch_Click(object sender, ImageClickEventArgs e)
    //{
        
    //    Response.Redirect("GN_Travels.aspx?HotKey=" + txtSearch.Value, false);
    //}
}
